/*
 * MainPanel.java
 *
 * Created on August 21, 2006, 8:21 PM
 */

package org.glossitope.container;

import java.awt.event.ActionEvent;

import javax.swing.Action;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

import org.jdesktop.swingx.JXBoxPanel;
import org.jdesktop.swingx.JXBusyLabel;
import org.jdesktop.swingx.JXButton;
import org.jdesktop.swingx.JXPanel;
import org.jdesktop.swingx.painter.CompoundPainter;

import org.glossitope.container.security.DockSkinner;

/**
 *
 * @author  joshy
 */
public class MainPanel extends javax.swing.JPanel {
    public enum DockingSide { Left, Right };
    private DockingSide side = DockingSide.Right;
    public Core main;
    
    
    /** Creates new form MainPanel */
    public MainPanel() {
        this(null);
    }
    
    public MainPanel(Core main) {
        setMain(main);
        initComponents();
        
        
        logoButton.setText("");
        //logoButton.setIcon(new ImageIcon(getClass().getResource("/images/logo 1.png")));
        
        JXButton logo = (JXButton) logoButton;
        logo.setContentAreaFilled(false);
        //GradientPaint grad = new GradientPaint(new Point(0,0), Color.GRAY, new Point(10,0), Color.WHITE);
        //MattePainter bg = new MattePainter(grad);
        //bg.setSnapPaint(true);
        
        //Painter comp = logo.getForegroundPainter();
        //CompoundPainter cp = new CompoundPainter(bg,comp);
        //logo.setForegroundPainter(cp);
        miniModePanel.setLayout(new BoxLayout(miniModePanel,BoxLayout.Y_AXIS));
        
        //stripButtonLeft.addActionListener(main.getCollapseWindowAction());
        //stripButtonRight.addActionListener(main.getCollapseWindowAction());
        logoButton.addActionListener(main.getCollapseWindowAction());
        
        ((JXButton)logoButton).setBackgroundPainter(new CompoundPainter());
        ((JXPanel)dockPanel).setBackgroundPainter(new CompoundPainter());
        
        DockSkinner.skinDock(this);
        
    }
    
    public void setMain(Core main) {
        this.main = main;
    }
    
    public Action getPreferencesAction() {
        return main.getPreferencesAction();
    }
    
    public Action getShowManageDialogAction() {
        return main.getShowManageDialogAction();
    }
    
    public Action getQuitAction() {
        return main.getQuitAction();
    }
    
    public Action getCollapseWindowAction() {
        return main.getCollapseWindowAction();
    }
    
    public DockingSide getDockingSide() {
        return this.side;
    }
    
    public void setDockingSide(DockingSide side) {
        this.side = side;
        main.getWindowManager().setDockingSide(side);
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        collapseButton = new javax.swing.JButton();
        dockPanel = new JXBoxPanel();
        manageButton = new JXButton();
        logoButton = new JXButton();
        quitButton = new JXButton();
        miniModePanel = new javax.swing.JPanel();
        loadingSpinner = new org.jdesktop.swingx.JXBusyLabel();

        collapseButton.setAction(getCollapseWindowAction());
        collapseButton.setText("<");
        collapseButton.setBorder(null);
        collapseButton.setBorderPainted(false);
        collapseButton.setOpaque(false);
        collapseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                collapseButtonActionPerformed(evt);
            }
        });

        setLayout(new java.awt.BorderLayout());

        dockPanel.setBackground(new java.awt.Color(102, 255, 102));
        dockPanel.setPreferredSize(new java.awt.Dimension(180, 500));
        dockPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dockPanelMouseClicked(evt);
            }
        });
        dockPanel.setLayout(new java.awt.GridBagLayout());

        manageButton.setAction(getShowManageDialogAction());
        manageButton.setFont(new java.awt.Font("Helvetica", 0, 14));
        manageButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/skins/dock/orange/images/configure.png"))); // NOI18N
        manageButton.setText("Setup");
        manageButton.setToolTipText("Manage Widgets and Preferences");
        manageButton.setBorder(null);
        manageButton.setBorderPainted(false);
        manageButton.setOpaque(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        dockPanel.add(manageButton, gridBagConstraints);

        logoButton.setBackground(new java.awt.Color(255, 51, 51));
        logoButton.setBorderPainted(false);
        logoButton.setContentAreaFilled(false);
        logoButton.setFocusable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        dockPanel.add(logoButton, gridBagConstraints);

        quitButton.setAction(getQuitAction());
        quitButton.setFont(new java.awt.Font("Helvetica", 0, 14));
        quitButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/skins/dock/orange/images/close.png"))); // NOI18N
        quitButton.setText("Quit");
        quitButton.setToolTipText("Quit");
        quitButton.setBorder(null);
        quitButton.setBorderPainted(false);
        quitButton.setOpaque(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        dockPanel.add(quitButton, gridBagConstraints);

        miniModePanel.setOpaque(false);
        miniModePanel.setLayout(new java.awt.GridLayout(20, 1));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weightx = 10.0;
        gridBagConstraints.weighty = 10.0;
        dockPanel.add(miniModePanel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
        dockPanel.add(loadingSpinner, gridBagConstraints);

        add(dockPanel, java.awt.BorderLayout.WEST);
    }// </editor-fold>//GEN-END:initComponents

    private void dockPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dockPanelMouseClicked
        
        main.getCollapseWindowAction().actionPerformed(
                new ActionEvent(this,-1,"toggle"));
        // TODO add your handling code here:
    }//GEN-LAST:event_dockPanelMouseClicked
    
    private void collapseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_collapseButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_collapseButtonActionPerformed
    
    public int getDockWidth() {
        return dockPanel.getWidth();
    }
    
    public JPanel getDockPanel() {
        return miniModePanel;
    }
    
    public JXBusyLabel getSpinner() {
        return loadingSpinner;
    }
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton collapseButton;
    public javax.swing.JPanel dockPanel;
    private org.jdesktop.swingx.JXBusyLabel loadingSpinner;
    public javax.swing.JButton logoButton;
    public javax.swing.JButton manageButton;
    private javax.swing.JPanel miniModePanel;
    public javax.swing.JButton quitButton;
    // End of variables declaration//GEN-END:variables
    
    
}
